package com.example.cloud.encoder;

import com.alibaba.fastjson.JSON;
import com.example.cloud.pojo.Message;

import javax.websocket.EncodeException;
import javax.websocket.Encoder;
import javax.websocket.EndpointConfig;

/**
 * Created by wt on 2018/11/23.
 */
public class ServerEncoder implements Encoder.Text<Message> {

    @Override
    public void destroy() {
    }

    @Override
    public void init(EndpointConfig arg0) {
    }

    @Override
    public String encode(Message message) throws EncodeException {
        try {
            return JSON.toJSONString(message);
        } catch (Exception e) {
            return null;
        }
    }
}
